﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using System.Windows.Shapes;

namespace Heyo.Controls
{
    public class TagLabel : Label
    {
        public TagLabel()
        {
            Padding = new Thickness(6,0,6,0);
            Margin=new Thickness(2);
            VerticalContentAlignment = VerticalAlignment.Center;
            HorizontalContentAlignment = HorizontalAlignment.Center;
            Background = new SolidColorBrush(Colors.LightBlue);
            Foreground = Brushes.White;
            SizeChanged += TagLabel_SizeChanged;
        }

        private void TagLabel_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var element = (base.GetVisualChild(0) as Border);
            element.CornerRadius = new CornerRadius(e.NewSize.Height * 0.4);
        }

        //protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        //{
        //    base.OnRenderSizeChanged(sizeInfo);
        //    _backgroundRect.Width = sizeInfo.NewSize.Width;
        //    _backgroundRect.Height = sizeInfo.NewSize.Height;
        //}

        //private readonly Rectangle _backgroundRect = new Rectangle();
        //protected override int VisualChildrenCount => base.VisualChildrenCount + 1;

        //protected override Visual GetVisualChild(int index)
        //{
        //    return index == 0 ? _backgroundRect : base.GetVisualChild(index - 1);
        //}

        //protected override Size MeasureOverride(Size availableSize)
        //{
        //    //Console.WriteLine(availableSize);
        //    var element = (base.GetVisualChild(0) as UIElement);
        //    element?.Measure(availableSize); ;


        //    return element.DesiredSize;
        //}

    }
}
